/* 
 * Autores:
 *      Jonathan Lopez  11106
 *      Jorge Martínez  11237
 * 
 * Ultima revision: $Rev$
 *      Fecha: $Date$
 * 
 * Archivo: FramePrincipal.java
 */


package GUI;

import java.io.IOException;
import javax.swing.JPanel;
import Servicios.*;
import Datos.CSV.*;
import javax.swing.JOptionPane;

/**
 * Contiene el Frame Principal que estaran utilizando todos los paneles de la
 * GUI.
 * 
 * @author Jorge
 * @author Jonathan
 */
public class FramePrincipal extends javax.swing.JFrame {
    
    private static FramePrincipal frmPrincipal = null;
    private static Servicios servicios = null;
    
    /**
     * Bloque de iniciacion estatico
     */
    static{
        try {
            servicios = new Servicios(null, 
                    new ProveedorDatosCSV("usuarios.csv", "datos.csv") );
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null,
                    "No se pudieron crear o localizar los archivos de datos.",
                    "Error fatal", JOptionPane.ERROR_MESSAGE );
            System.exit(-1);
        }
    }
    
    /** Creates new form FramePrincipal */
    public FramePrincipal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Caja Encriptada de Datos (CED)");
        setLocationByPlatform(true);
        setName("frmPrincipal"); // NOI18N
        setResizable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("GTK+".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                frmPrincipal = new FramePrincipal();
                frmPrincipal.setContentPane( new InicioSesion(frmPrincipal) );
                frmPrincipal.pack();
                frmPrincipal.setVisible(true);
                //new FramePrincipal().setVisible(true);
            }
        });
    }
    
    /**
     * Cambia el Panel que se esta utilizando actualmente por el Frame y
     * devuelve el anterior.
     * @param nuevoPanel Nuevo panel a utilizar.
     * @return Panel que se estaba utilizando.
     */
    public static JPanel cambiarPanel( JPanel nuevoPanel ){
        // Validar
        if( frmPrincipal == null || nuevoPanel == null )
            return null;
        
        JPanel anterior = (JPanel)frmPrincipal.getContentPane();
        
        // Realizar animacion
        // TODO
        frmPrincipal.setContentPane( nuevoPanel );
        frmPrincipal.pack();
        
        return anterior;
    }
    
    /**
     * @return Devuelve la variable de servicios que esta utilizando el Frame
     * Principal.
     */
    public static Servicios obtenerServicios(){
        return servicios;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
